package zkk.com.mengqu.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

import zkk.com.mengqu.R;

/**
 * 饭友圈页面
 */
public class CircleFriendsFragment extends Fragment implements View.OnClickListener{
    private View view;
    private Context context;
    private ImageView camera;
    private List<Fragment> mFragmentList = new ArrayList<>();
    private TabLayout tableLayout;//导航栏
    private ViewPager viewPager;
    private ApnFragmentAdapter mAdapter;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        view=inflater.inflate(R.layout.fragment_circle_friends, container,false);
        context = getContext();

        mFragmentList.add(new CircleFriendFragment());//饭友
        mFragmentList.add(new CircleFriendSubscribeFragment());//订阅

        tableLayout = (TabLayout)view.findViewById(R.id.commit_tableLayout);
        viewPager = (ViewPager)view.findViewById(R.id.commit_viewPager);

        mAdapter = new ApnFragmentAdapter(getFragmentManager());
        viewPager.setAdapter(mAdapter);
        tableLayout.setupWithViewPager(viewPager);
        tableLayout.setTabMode(TabLayout.MODE_FIXED);

        return view;
    }

    public void initView(){
        camera = (ImageView) view.findViewById(R.id.iv_camera);

        camera.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.iv_camera:
                Toast.makeText(context , "拍照" , Toast.LENGTH_LONG).show();
                break;
        }
    }

    private class ApnFragmentAdapter extends FragmentPagerAdapter {
        CharSequence[] TITLE = new CharSequence[]{"饭友","订阅"};

        public ApnFragmentAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return mFragmentList.get(position);
        }

        @Override
        public int getCount() {
            return TITLE.length;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return TITLE[position];
        }
    }
}
